use crate::core::model::data::Data;
use crate::core::base;
use regex::Captures;

/// str以逗号分割的参数转为vec
pub fn args_to_vec(yuzu: &str, args_str: &str) -> Vec<Data> {
    let args = args_str.split(',');
    let mut v = vec![];
    for arg in args {
        //削减前后空格并匹配基本数据
        let data = data_transfer(yuzu, arg.trim());
        v.push(data);
    }
    v
}

/// 将Captures中的匹配结果取出
pub fn capture_str(capture: &Captures, index: usize) -> String {
    capture.get(index).unwrap().as_str().to_string()
}

///
pub fn data_transfer(yuzu: &str, value: &str) -> Data {
    match Data::transfer(yuzu, value) {
        Ok(data) => { data }
        Err(e) => {
            base::log().err_exit(format!("{}", e));
        }
    }
}

